﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace syc.Sale
{
    public partial class 月质量异议明细表 : System.Web.UI.Page
    {
        string sql = @" select 供货单位ID,原料供货单位.名称 as 供货单位,
 [dbo].[原料本月异议量](102,供货单位ID,@年度,@月份) as 套管N80数量,
[dbo].[原料单价] (102,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](102,供货单位ID,@年度,@月份) as 套管N80金额,
 [dbo].[原料本月异议量](2,供货单位ID,@年度,@月份) as 套管数量,
[dbo].[原料单价] (2,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](2,供货单位ID,@年度,@月份) as 套管金额,
[dbo].[原料本月异议量](1,供货单位ID,@年度,@月份) as 油管数量,
[dbo].[原料单价] (1,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](1,供货单位ID,@年度,@月份) as 油管金额,
[dbo].[原料本月异议量](4,供货单位ID,@年度,@月份) as 套管接箍料数量,
[dbo].[原料单价] (4,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](4,供货单位ID,@年度,@月份) as 套管接箍料金额,
[dbo].[原料本月异议量](3,供货单位ID,@年度,@月份) as 油管接箍料数量,
[dbo].[原料单价] (3,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](3,供货单位ID,@年度,@月份) as 油管接箍料金额,
([dbo].[原料单价] (1,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](1,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (2,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](2,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (3,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](3,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (4,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](4,供货单位ID,@年度,@月份)) as 合计金额,
([dbo].[原料单价] (1,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](1,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (2,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](2,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (3,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](3,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (4,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](4,供货单位ID,@年度,@月份))*1.17 as 合计含税金额
  from 原料异议库 inner join 原料供货单位 on 原料异议库.供货单位ID=原料供货单位.ID group by 供货单位ID,原料供货单位.名称";
        protected double 套管N80数量合计;
        protected double 套管N80金额合计;
        protected double 套管数量合计;
        protected double 套管金额合计;
        protected double 油管数量合计;
        protected double 油管金额合计;
        protected double 套管接箍料数量合计;
        protected double 套管接箍料金额合计;
        protected double 油管接箍料数量合计;
        protected double 油管接箍料金额合计;
        protected double 金额合计;
        protected double 金额含税合计;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Message.Text = "·准备就绪";

            if (!this.IsPostBack)
            {
               this.Month.SelectedValue = DateTime.Today.Month.ToString();
               this.Year0.SelectedValue = DateTime.Today.Year.ToString();
               sql = sql.Replace("@年度", this.Year0.SelectedValue);
               sql = sql.Replace("@月份", this.Month.SelectedValue);
                this.SqlDataSource1.SelectCommand = sql;
                this.ViewState["SelectCommand"] = sql;
            }
            this.GridView1.Attributes.Add("bordercolor", "Black");
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }
        //年份变化时  
        protected void Year0_SelectedIndexChanged(object sender, EventArgs e)
        {
            sql = sql.Replace("@年度", this.Year0.SelectedValue);
            sql = sql.Replace("@月份", this.Month.SelectedValue);
            this.SqlDataSource1.SelectCommand = sql;
            this.ViewState["SelectCommand"] = sql;
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }
        //月份变化时
        protected void Month_SelectedIndexChanged(object sender, EventArgs e)
        {
            sql = sql.Replace("@年度", this.Year0.SelectedValue);
            sql = sql.Replace("@月份", this.Month.SelectedValue);
            this.SqlDataSource1.SelectCommand = sql;
            this.ViewState["SelectCommand"] = sql;
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                套管N80数量合计 += Convert.ToDouble(e.Row.Cells[2].Text);
                套管N80金额合计 += Convert.ToDouble(e.Row.Cells[3].Text);
                套管数量合计 += Convert.ToDouble(e.Row.Cells[4].Text);
                套管金额合计 += Convert.ToDouble(e.Row.Cells[5].Text);
                油管数量合计 += Convert.ToDouble(e.Row.Cells[6].Text);
                油管金额合计 += Convert.ToDouble(e.Row.Cells[7].Text);
                套管接箍料数量合计 += Convert.ToDouble(e.Row.Cells[8].Text);
                套管接箍料金额合计 += Convert.ToDouble(e.Row.Cells[9].Text);
                油管接箍料数量合计 += Convert.ToDouble(e.Row.Cells[10].Text);
                油管接箍料金额合计 += Convert.ToDouble(e.Row.Cells[11].Text);
                金额合计 += Convert.ToDouble(e.Row.Cells[12].Text);              
            }


        }
       
        //设置表头及页脚
        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.Header)
            {
                //第一行表头
                TableCellCollection tcHeader = e.Row.Cells;
                tcHeader.Clear();
                tcHeader.Add(new TableHeaderCell());
                tcHeader[0].Attributes.Add("rowspan", "2"); //跨2Row
                tcHeader[0].Text = "序号";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[1].Attributes.Add("rowspan", "2"); //跨2Row
                tcHeader[1].Text = "供货单位";           
                tcHeader.Add(new TableHeaderCell());
                tcHeader[2].Attributes.Add("colspan", "2"); //跨3Col
                tcHeader[2].Text = "套管N80";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[3].Attributes.Add("colspan", "2"); //跨3Col
                tcHeader[3].Text = "套管J55";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[4].Attributes.Add("colspan", "2"); //跨3Col
                tcHeader[4].Text = "油管";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[5].Attributes.Add("colspan", "2"); //跨3Col
                tcHeader[5].Text = "套接箍料";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[6].Attributes.Add("colspan", "2"); //跨3Col
                tcHeader[6].Text = "油接箍料";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[7].Attributes.Add("rowspan", "2"); //跨2Row
                tcHeader[7].Text = "合计金额";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[8].Attributes.Add("rowspan", "2"); //跨2Row
                tcHeader[8].Text = "合计金额(含税)</th></tr><tr>";


                //第二行表头
                tcHeader.Add(new TableHeaderCell());
                tcHeader[9].Attributes.Add("colspan", "1");
                tcHeader[9].Text = "数量";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[10].Attributes.Add("colspan", "1");
                tcHeader[10].Text = "金额";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[11].Attributes.Add("colspan", "1");
                tcHeader[11].Text = "数量";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[12].Attributes.Add("colspan", "1");
                tcHeader[12].Text = "金额";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[13].Attributes.Add("colspan", "1");
                tcHeader[13].Text = "数量";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[14].Attributes.Add("colspan", "1");
                tcHeader[14].Text = "金额";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[15].Attributes.Add("colspan", "1");
                tcHeader[15].Text = "数量";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[16].Attributes.Add("colspan", "1");
                tcHeader[16].Text = "金额";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[17].Attributes.Add("colspan", "1");
                tcHeader[17].Text = "数量";
                tcHeader.Add(new TableHeaderCell());
                tcHeader[18].Attributes.Add("colspan", "1");
                tcHeader[18].Text = "金额</th></tr><tr>";
            }
            if (e.Row.RowType == DataControlRowType.Footer)//判断此行是否是页尾，如果是则开始统计数据
            {
               // 套管数量合计 = ReturnTotal(2).ToString();
             
                TableCellCollection tcFooter = e.Row.Cells;
                tcFooter.Clear();
                tcFooter.Add(new TableHeaderCell());
                tcFooter[0].Attributes.Add("colspan", "2"); //跨2col
                tcFooter[0].Text = "合计";
                tcFooter.Add(new TableHeaderCell());
                tcFooter[1].Attributes.Add("colspan", "1");
                tcFooter[1].Attributes.Add("align", "right"); ;
                tcFooter[1].Text = 套管N80数量合计.ToString();
                tcFooter.Add(new TableHeaderCell());
                tcFooter[2].Attributes.Add("colspan", "1");
                tcFooter[2].Text = 套管N80金额合计.ToString();

                tcFooter.Add(new TableHeaderCell());
                tcFooter[3].Attributes.Add("colspan", "1");
                tcFooter[3].Attributes.Add("align", "right"); ;
                tcFooter[3].Text = 套管数量合计.ToString();
                tcFooter.Add(new TableHeaderCell());
                tcFooter[4].Attributes.Add("colspan", "1");
                tcFooter[4].Text = 套管金额合计.ToString();

                tcFooter.Add(new TableHeaderCell());
                tcFooter[5].Attributes.Add("colspan", "1");
                tcFooter[5].Attributes.Add("align", "right"); 
                tcFooter[5].Text = 油管数量合计.ToString();
                tcFooter.Add(new TableHeaderCell());
                tcFooter[6].Attributes.Add("colspan", "1");
                tcFooter[6].Text = 油管金额合计.ToString();

                tcFooter.Add(new TableHeaderCell());
                tcFooter[7].Attributes.Add("colspan", "1");
                tcFooter[7].Attributes.Add("align", "right"); 
                tcFooter[7].Text = 套管接箍料数量合计.ToString();
                tcFooter.Add(new TableHeaderCell());
                tcFooter[8].Attributes.Add("colspan", "1");
                tcFooter[8].Text = 套管接箍料金额合计.ToString();

                tcFooter.Add(new TableHeaderCell());
                tcFooter[9].Attributes.Add("colspan", "1");
                tcFooter[9].Attributes.Add("align", "right"); 
                tcFooter[9].Text = 油管接箍料数量合计.ToString();
                tcFooter.Add(new TableHeaderCell());
                tcFooter[10].Attributes.Add("colspan", "1");
                tcFooter[10].Text = 油管接箍料金额合计.ToString();
                tcFooter.Add(new TableHeaderCell());
                tcFooter[11].Attributes.Add("colspan", "1"); //跨2Row
                tcFooter[11].Text = 金额合计.ToString();
                tcFooter.Add(new TableHeaderCell());
                tcFooter[12].Attributes.Add("colspan", "1"); //跨2Row
                tcFooter[12].Text = 金额含税合计 + "</th></tr>";
            }
        }

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            string part1 =
              @"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel'
xmlns='http://www.w3.org/TR/REC-html40'>
<meta http-equiv=Content-Type content='text/html; charset=utf-8'>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Chinese User</o:Author>
  <o:LastAuthor>Chinese User</o:LastAuthor>
  <o:LastPrinted>2010-09-25T01:57:58Z</o:LastPrinted>
  <o:Created>2010-09-25T01:52:18Z</o:Created>
  <o:LastSaved>2010-09-25T02:27:52Z</o:LastSaved>
  <o:Company>Chinese ORG</o:Company>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<style>
<!--table
	{mso-displayed-decimal-separator:'\.';
	mso-displayed-thousand-separator:'\,';}
@page
	{margin:.66in .49in 1.0in .55in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-page-orientation:landscape;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl24
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl25
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl26
	{mso-style-parent:style0;
	text-align:left;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl27
	{mso-style-parent:style0;
	text-align:right;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl28
	{mso-style-parent:style0;
	text-align:right;
	border:.5pt solid windowtext;}
.xl29
	{mso-style-parent:style0;
	text-align:center;
	border:.5pt solid windowtext;}
.xl30
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl31
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl32
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl33
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl34
	{mso-style-parent:style0;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl35
	{mso-style-parent:style0;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>14</x:ActiveRow>
       <x:ActiveCol>7</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>7005</x:WindowHeight>
  <x:WindowWidth>11460</x:WindowWidth>
  <x:WindowTopX>480</x:WindowTopX>
  <x:WindowTopY>210</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=1015 style='border-collapse:
 collapse;table-layout:fixed;width:763pt'>
 <col width=34 style='mso-width-source:userset;mso-width-alt:1088;width:26pt'>
 <col width=78 style='mso-width-source:userset;mso-width-alt:2496;width:59pt'>
 <col width=69 style='mso-width-source:userset;mso-width-alt:2208;width:52pt'>
 <col width=72 style='mso-width-source:userset;mso-width-alt:2304;width:54pt'>
 <col width=70 span=2 style='mso-width-source:userset;mso-width-alt:2240;
 width:53pt'>
 <col width=68 style='mso-width-source:userset;mso-width-alt:2176;width:51pt'>
 <col width=71 style='mso-width-source:userset;mso-width-alt:2272;width:53pt'>
 <col width=69 style='mso-width-source:userset;mso-width-alt:2208;width:52pt'>
 <col width=71 style='mso-width-source:userset;mso-width-alt:2272;width:53pt'>
 <col width=69 style='mso-width-source:userset;mso-width-alt:2208;width:52pt'>
 <col width=71 style='mso-width-source:userset;mso-width-alt:2272;width:53pt'>
 <col width=76 style='mso-width-source:userset;mso-width-alt:2432;width:57pt'>
 <col width=127 style='mso-width-source:userset;mso-width-alt:4064;width:95pt'>
 <tr height=38 style='mso-height-source:userset;height:28.5pt'>
  <td colspan=14 height=38 class=xl30 width=1015 style='height:28.5pt;
  width:763pt'>@年度年@月份月库房登记有质量异议明细表</td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td rowspan=2 height=38 class=xl31 style='border-bottom:.5pt solid black;
  height:28.5pt;border-top:none'>序号</td>
  <td rowspan=2 class=xl31 style='border-bottom:.5pt solid black;border-top:
  none'>供货单位</td>
  <td colspan=2 class=xl32 style='border-right:.5pt solid black;border-left:
  none'>套管N80</td>
  <td colspan=2 class=xl32 style='border-right:.5pt solid black;border-left:
  none'>套管J55</td>
  <td colspan=2 class=xl32 style='border-right:.5pt solid black;border-left:
  none'>油管</td>
  <td colspan=2 class=xl32 style='border-right:.5pt solid black;border-left:
  none'>套接箍料</td>
  <td colspan=2 class=xl32 style='border-right:.5pt solid black;border-left:
  none'>油接箍料</td>
  <td rowspan=2 class=xl31 style='border-bottom:.5pt solid black;border-top:
  none'>合计金额</td>
  <td rowspan=2 class=xl34 style='border-bottom:.5pt solid black;border-top:
  none'>合计金额（含税）</td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td height=19 class=xl24 style='height:14.25pt'>数量</td>
  <td class=xl24>金额</td>
  <td class=xl24>数量</td>
  <td class=xl24>金额</td>
  <td class=xl24>数量</td>
  <td class=xl24>金额</td>
  <td class=xl24>数量</td>
  <td class=xl24>金额</td>
  <td class=xl24>数量</td>
  <td class=xl24>金额</td>
 </tr>";

            string part3 = @" <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=34 style='width:26pt'></td>
  <td width=78 style='width:59pt'></td>
  <td width=69 style='width:52pt'></td>
  <td width=72 style='width:54pt'></td>
  <td width=70 style='width:53pt'></td>
  <td width=70 style='width:53pt'></td>
  <td width=68 style='width:51pt'></td>
  <td width=71 style='width:53pt'></td>
  <td width=69 style='width:52pt'></td>
  <td width=71 style='width:53pt'></td>
  <td width=69 style='width:52pt'></td>
  <td width=71 style='width:53pt'></td>
  <td width=76 style='width:57pt'></td>
  <td width=127 style='width:95pt'></td>
 </tr>
 <![endif]>
</table>
</body>
</html>";          
            Response.Charset = "utf-8";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "application/ms-excel";
            Response.AddHeader("content-disposition", "attachment; filename=\"" + Server.UrlEncode("质量异议明细表") + ".xls\"");         
            string  part = part1. Replace("@年度", this.Year0.SelectedItem.Text).Replace("@月份", this.Month.SelectedItem.Text);
            Response.Write(part);
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            string sql = @"select 供货单位ID,原料供货单位.名称 as 供货单位,
 [dbo].[原料本月异议量](102,供货单位ID,@年度,@月份) as 套管N80数量,
[dbo].[原料单价] (102,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](102,供货单位ID,@年度,@月份) as 套管N80金额,
 [dbo].[原料本月异议量](2,供货单位ID,@年度,@月份) as 套管数量,
[dbo].[原料单价] (2,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](2,供货单位ID,@年度,@月份) as 套管金额,
[dbo].[原料本月异议量](1,供货单位ID,@年度,@月份) as 油管数量,
[dbo].[原料单价] (1,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](1,供货单位ID,@年度,@月份) as 油管金额,
[dbo].[原料本月异议量](4,供货单位ID,@年度,@月份) as 套管接箍料数量,
[dbo].[原料单价] (4,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](4,供货单位ID,@年度,@月份) as 套管接箍料金额,
[dbo].[原料本月异议量](3,供货单位ID,@年度,@月份) as 油管接箍料数量,
[dbo].[原料单价] (3,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](3,供货单位ID,@年度,@月份) as 油管接箍料金额,
([dbo].[原料单价] (1,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](1,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (2,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](2,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (3,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](3,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (4,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](4,供货单位ID,@年度,@月份)) as 合计金额,
([dbo].[原料单价] (1,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](1,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (2,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](2,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (3,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](3,供货单位ID,@年度,@月份)+
[dbo].[原料单价] (4,供货单位ID,@年度,@月份)*[dbo].[原料本月异议量](4,供货单位ID,@年度,@月份))*1.17 as 合计含税金额
  from 原料异议库 inner join 原料供货单位 on 原料异议库.供货单位ID=原料供货单位.ID group by 供货单位ID,原料供货单位.名称";
            sql = sql.Replace("@年度", this.Year0.SelectedValue);
            sql = sql.Replace("@月份", this.Month.SelectedValue);
            Cmd.CommandText = sql;        
            SqlDataReader Reader = Cmd.ExecuteReader();
            int i = 0;       
            while (Reader.Read())
            {               
              i++;
              Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl25 style='height:14.25pt;border-top:none'>" + i + "</td>");
              Response.Write("<td class=xl26  style='border-top:none;border-left:none'>" + Reader.GetString(1) + "</td>");
              Response.Write("<td class=xl27 style='border-top:none;border-left:none'>" + Reader.GetDouble(2) + "</td>");
              Response.Write("<td class=xl24 style='border-top:none;border-left:none'>" + Reader.GetDouble(3) + "</td>");
              Response.Write("<td class=xl27 style='border-top:none;border-left:none'>" + Reader.GetDouble(4) + "</td>");
              Response.Write("<td class=xl24 style='border-top:none;border-left:none'>" + Reader.GetDouble(5) + "</td>");
              Response.Write("<td class=xl27 style='border-top:none;border-left:none'>" + Reader.GetDouble(6) + "</td>");
              Response.Write("<td class=xl24 style='border-top:none;border-left:none'>" + Reader.GetDouble(7) + "</td>");
              Response.Write("<td class=xl27 style='border-top:none;border-left:none'>" + Reader.GetDouble(8) + "</td>");
              Response.Write("<td class=xl24 style='border-top:none;border-left:none'>" + Reader.GetDouble(9) + "</td>");
              Response.Write("<td class=xl27 style='border-top:none;border-left:none'>" + Reader.GetDouble(10) + "</td>");
              Response.Write("<td class=xl24 style='border-top:none;border-left:none'>" + Reader.GetDouble(11) + "</td>");
              Response.Write("<td class=xl24 style='border-top:none;border-left:none'>" + Reader.GetDouble(12) + "</td>");
              Response.Write("<td class=xl24 style='border-top:none;border-left:none'>" + Reader.GetDouble(13) + "</td>");
              套管N80数量合计 += Reader.GetDouble(2);
              套管N80金额合计 += Reader.GetDouble(3);
              套管数量合计 += Reader.GetDouble(4);
              套管金额合计 += Reader.GetDouble(5);
              油管数量合计 += Reader.GetDouble(6);
              油管金额合计 += Reader.GetDouble(7);
              套管接箍料数量合计 += Reader.GetDouble(8);
              套管接箍料金额合计 += Reader.GetDouble(9);
              油管接箍料数量合计 += Reader.GetDouble(10);
              油管接箍料金额合计 += Reader.GetDouble(11);
              金额合计 += Reader.GetDouble(12);
              金额含税合计 += Reader.GetDouble(13);
            }
            Response.Write("<tr height=19 style='height:14.25pt'><td colspan=2 height=19 class=xl29 style='height:14.25pt'>合计</td>");
            Response.Write("<td class=xl28>" + 套管N80数量合计 + "</td>");
            Response.Write("<td class=xl29>" + 套管N80金额合计 + "</td>");
            Response.Write("<td class=xl28>" + 套管数量合计 + "</td>");
            Response.Write("<td class=xl29>" + 套管金额合计 + "</td>");
            Response.Write("<td class=xl28>" + 油管数量合计 + "</td>");
            Response.Write("<td class=xl29>" + 油管金额合计 + "</td>");
            Response.Write("<td class=xl28>" + 套管接箍料数量合计 + "</td>");
            Response.Write("<td class=xl29>" + 套管接箍料金额合计 + "</td>");
            Response.Write("<td class=xl28>" + 油管接箍料数量合计 + "</td>");
            Response.Write("<td class=xl29>" + 油管接箍料金额合计 + "</td>");
            Response.Write("<td class=xl29>" + 金额合计 + "</td>");
            Response.Write("<td class=xl29>" + 金额含税合计 + "</td>");        
            Response.Write(part3);
            Response.End();
        }

        
         
    }
}
